package com.jhws.common.base.api;

import com.aliyuncs.sts.model.v20150401.AssumeRoleResponse;
import com.jhws.business.aliyun.service.OSSClientService;
import com.jhws.common.base.bo.JsonRespData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/v2/oss")
public class OssApi {

    @Resource
    private OSSClientService ossClientService;

    /**
     * oss key 返回接口
     * @return
     * @throws Exception
     */
    @RequestMapping("getCredentials")
    @ResponseBody
    public JsonRespData getCredentials() throws Exception {

        AssumeRoleResponse.Credentials credentials = ossClientService.getCredentials();
        Map<String, Object> map = new HashMap<>();
        map.put("credentials", credentials);
        map.put("bucketGerneralfiles", ossClientService.getBucketNameGerneralfiles());
        return new JsonRespData("", 1, map);
    }
}
